package com.hwua.tonyshop.controller.fg;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hwua.tonyshop.criteria.BannerCriteria;
import com.hwua.tonyshop.criteria.GoodsInfoCriteria;
import com.hwua.tonyshop.entity.mojo.BannerAO;
import com.hwua.tonyshop.entity.mojo.GoodsInfoAO;
import com.hwua.tonyshop.service.IBannerService;
import com.hwua.tonyshop.service.IGoodsInfoService;
import com.slkj.autocode.entity.ServiceResult;

@Controller
@RequestMapping(value = "/fore/goodsClass")
public class GoodsClassController {
	@Resource
	IBannerService bannerService;
	@Resource
	IGoodsInfoService goodsInfoService;
	/**
	 * 跳转到商品分类页面
	 * @param model
	 * @param request
	 * @param response
	 * @return
	 */
		@RequestMapping(value = "/toGoodsClassPage", method = { RequestMethod.GET, RequestMethod.POST })
		public String toGoodsClassPage(String token,Integer classId,Model model,HttpServletRequest request,HttpServletResponse response) {
			model.addAttribute("token",token);
			model.addAttribute("classId",classId);
			return "foreground/page/phone";
		}
		//获取轮播图
		@RequestMapping(value = "/getBanners", method = { RequestMethod.GET, RequestMethod.POST })
		@ResponseBody
		public ServiceResult<List<BannerAO>> getBanners(Model model,HttpServletRequest request,HttpServletResponse response) {
			BannerCriteria criteria = new BannerCriteria();
			criteria.andLocationEquals("2").andStateEquals("0");
			return bannerService.selectByCriteria(criteria);
		}
		//获取该类对应的商品
		@RequestMapping(value = "/getMenuGoodsInfos", method = { RequestMethod.GET, RequestMethod.POST })
		@ResponseBody
		public ServiceResult<List<GoodsInfoAO>> getMenuGoodsInfos(Integer classId,Model model,HttpServletRequest request,HttpServletResponse response) {
			GoodsInfoCriteria criteria = new GoodsInfoCriteria();
			criteria.andClassIdEquals(classId).andStateEquals("0");
			return goodsInfoService.selectByCriteria(criteria);
		}
}
